package ae.pcfc.etks.online.web.controller.admin.general.client.report;

/* $Id: ReportController 
 * Copyright (C) 2011, Trakhees
 *  
 *  History
 *
 * Date  			Author 					Remarks
 * -------------------------------------------------------------
 * April 13, 2011 	Neha_Chauhan 	        Created
 *
 */

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;

import ae.pcfc.etks.online.common.delegate.ReportDelegate;
import ae.pcfc.etks.online.common.vo.LabelVO;
import ae.pcfc.etks.online.web.ConstantsAdmin;
import ae.pcfc.etks.online.web.ViewPath;
import ae.pcfc.etks.online.web.ViewUtils;
import ae.pcfc.etks.online.web.controller.BaseController;
import ae.pcfc.etks.online.web.controller.user.general.company.UserCompanyController;
import ae.pcfc.etks.online.web.model.AdminReport;
import ae.pcfc.etks.online.web.model.ClientCompanyRegistration;

/**
 * Controller that handles all {@link UserCompanyController}-related requests,
 * i.e.: all requests for admin/general/report/*
 * 
 * @author Neha Chauhan
 */

@Controller
@RequestMapping(ViewPath.ADMIN_REPORT)
public class AdminReportController extends BaseController {

	private ReportDelegate reportDelegate;

	@Resource(name = "reportDelegate")
	public void setReportDelegate(ReportDelegate reportDelegate) {
		this.reportDelegate = reportDelegate;
	}

	@ModelAttribute(value = ConstantsAdmin.ADMIN_REPORT_MODEL_KEY)
	public AdminReport populateReport(HttpServletRequest request,
			@RequestParam(value = "id", required = false) String id) {

		return new AdminReport();

	}

	@ModelAttribute(ConstantsAdmin.ADMIN_REPORT_TYPE_MODEL_KEY)
	public List<LabelVO> populateAdminReportTypeList() {

		List<LabelVO> labelList = new ArrayList<LabelVO>();

		LabelVO labelVO = new LabelVO();
		labelVO.setId("C");
		labelVO.setLabelAr("List of Registered Companies - Ar");
		labelVO.setLabelEn("List of Registered Companies");
		labelList.add(labelVO);

		labelVO = new LabelVO();
		labelVO.setId("P");
		labelVO.setLabelAr("List of Registered Persons - Ar");
		labelVO.setLabelEn("List of Registered Persons");
		labelList.add(labelVO);

		return labelList;
	}

	/**
	 * Custom handler for displaying the form, i.e.: GET requests for
	 * /admin/general/report/ Note that this handler returns void instead of a
	 * {@link ModelAndView}, signifying a default logical view name should be
	 * selected by Spring MVC. The ui {@link Model} is supplied as a parameter
	 * to the method and populated with the new model object to be rendered.
	 * 
	 * 
	 * @see WEB-INF/jsp/admin/general/report/form.jsp
	 */

	@RequestMapping(value = "/form.htm", method = RequestMethod.GET)
	public void form(
			@ModelAttribute(value = ConstantsAdmin.ADMIN_REPORT_MODEL_KEY) AdminReport command) {

	}

	/**
	 * Custom handler for displaying the form, i.e.:POST requests for
	 * admin/general/report/form.jsp
	 * 
	 * @see #form(ClientCompanyRegistration)
	 * @see WEB-INF/jsp/admin/general/report/form.jsp
	 */

	@RequestMapping(method = RequestMethod.POST, value = "/form.htm")
	public String find(
			HttpServletRequest request,
			SessionStatus status,
			@ModelAttribute(value = ConstantsAdmin.ADMIN_REPORT_MODEL_KEY) @Valid AdminReport adminReport,
			BindingResult errors) {

		boolean isGenerate = WebUtils.hasSubmitParameter(request,
				ConstantsAdmin.GENERATE_BUTTON);

		if (isGenerate) {
			if (errors.hasErrors()) {

			}

		}
		return ViewUtils.DEFAULT_VIEW;
	}

}
